<?php
/**
 * Created by Ling.
 * Created on 2021/3/30 15:09
 * @email: L_ing1992@163.com
 */

namespace App\Exceptions;

use App\Http\Responses\RespCode;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class BusException extends \Exception
{
    /**
     * Exception constructor.
     * @param array $enum
     */
    public function __construct(array $enum = [])
    {
        parent::__construct($enum['msg'] ?? '失败', $enum['code'] ?? RespCode::FAILED);
    }

    /**
     * 重新渲染异常 ！！
     * @param Request $request
     * @return JsonResponse
     */
    public function render(Request $request): JsonResponse
    {
        return new JsonResponse(['code' => $this->code, 'msg' => $this->message]);
    }
}
